/**
 * 行程列表
 *
 */
define(["app", "comm/pager/PagerControl", "js/services/MessageBox", "js/services/MuseService"
    , "js/directives/DatetimePicker"
    , "js/controllers/trip/tripActivity/TripActivityCommon.js"], function (app) {

    var deps = ["$scope", "$state", "$modal", "MessageBox", "MuseService"];

    function controller ($scope, $state, $modal, MessageBox, MuseService) {
        //初始化查询对象 和 分页对象
        app.regsiterCacheData($scope, $state);
        $scope.queryObj = $scope.queryObj || {};
        $scope.pagerObj = $scope.pagerObj || {};

        //获取列表
        $scope.getObjList = function (pageNo, pageSize) {
            var curPage = pageNo || $scope.pagerObj.currentPage || 1;
            var param = {
                page: curPage, pageSize: pageSize || $scope.pagerObj.pageSize,
                param: {
                    driverName: $scope.queryObj.driverName || "",
                    driverTel: $scope.queryObj.driverTel || "",
                    routeName: $scope.queryObj.routeName || "",
                    carNo: $scope.queryObj.carNo || "",
                    createTimeStart: $scope.queryObj.createTimeStart || "",
                    createTimeEnd: $scope.queryObj.createTimeEnd || ""
                }
            };

            if ($scope.queryObj.state != undefined) {
                param.param.state = $scope.queryObj.state;
            }

            MuseService.postObj(baseServices_restfulUrl + "tripActivity/search.json", param).success(
                function (data, status, headers, config) {
                    // console.log(data);
                    if (data.state == 0) {
                        var page = data.data;
                        $scope.tripActivityList = page.data;

                        //分页器
                        $scope.pagerObj = PageCtrl().page($scope.pagerObj, page.total, curPage);
                    }
                });
        };

        $scope.getObjList();

        //新增
        $scope.add = function () {
            $state.go('tripActivityEdit');
        };

        //编辑
        $scope.edit = function (id) {
            $state.go('tripActivityEdit', {id: id});
        };

        $scope.pageChanged = function () {
            PageCtrl().check($scope.pagerObj);
            $scope.getObjList($scope.pagerObj.currentPage, $scope.pagerObj.pageSize);
        }
    }

    controller.$inject = deps;
    app.lazy.controller("TripActivityListController", controller);
});
